package com.flux.ui.main;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ListView;

import com.flux.R;
import com.flux.models.DataModel;
import com.flux.models.IDataModel;
import com.flux.models.bean.EventInfo;
import ui.base.BaseActivity;
import com.flux.ui.widget.MultipleStatusView;

import java.util.List;

public class MainActivity extends BaseActivity<MainConstant.Controller> implements MainConstant.View {

    private MultipleStatusView statusView;
    private EventInfoAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setupView();
    }

    @Override
    protected MainConstant.Controller createController() {
        IDataModel dataModel = new DataModel();
        return new MainController(this, dataModel);
    }

    @Override
    public void setController(MainConstant.Controller controller) {
        this.controller = controller;
    }


    // 视图设置
    private void setupView() {
        statusView = (MultipleStatusView) findViewById(R.id.status_view);
        ListView listView = (ListView) LayoutInflater.from(this).inflate(R.layout.main_list_layout, null);
        statusView.setContentView(listView);
        adapter = new EventInfoAdapter(this);
        listView.setAdapter(adapter);
    }

    @Override
    public void showLoading() {
        statusView.showLoading();
    }

    @Override
    public void showError() {
        statusView.showError();
    }

    @Override
    public void showContent(List<EventInfo> data) {
        statusView.showContent();
        adapter.setData(data);
    }
}
